﻿// -----------------------------------------------------------------------
// <copyright file="IdGenerator.cs" company="Zen Design Corp">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace Zen.BlackBerry.Common
{
	using System;
	using System.Collections.Generic;
	using System.Linq;
	using System.Text;

	/// <summary>
	/// Implementation of the <see cref="IIdGenerator"/> interface.
	/// </summary>
	public class IdGenerator : IIdGenerator
	{
		/// <summary>
		/// Initializes a new instance of the <see cref="IdGenerator"/> class.
		/// </summary>
		public IdGenerator()
		{
			DomainName = "debugdomain.local";
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="IdGenerator"/> class.
		/// </summary>
		/// <param name="domainName">
		/// Name of the domain used as a suffix to the ids generated by this
		/// instance.
		/// </param>
		public IdGenerator(string domainName)
		{
			DomainName = domainName;
		}

		/// <summary>
		/// Gets the name of the domain used as a suffix to the generated ids.
		/// </summary>
		/// <value>The name of the domain.</value>
		public string DomainName
		{
			get;
			private set;
		}

		#region IIdGenerator Members

		/// <summary>
		/// Generates a globally unique id.
		/// </summary>
		/// <returns>A globally unique id.</returns>
		/// <remarks>
		/// It is recommended that the id have a suffix containing the
		/// vendor domain name to ensure globally unique ids.
		/// </remarks>
		public string GenerateId()
		{
			return string.Format("{0:N}@{1}", Guid.NewGuid(), DomainName);
		}

		#endregion
	}
}
